﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections.ObjectModel;

namespace TinyCinema.UI.Pages.HumanResources
{
    /// <summary>
    /// Interaction logic for Configuration.xaml
    /// </summary>
    public partial class Configuration : Page
    {
        public StackPanel MainMenu { get; set; }
        public static DependencyProperty ContentFrameSourceProperty = DependencyProperty.Register("pagContentFrameSource", typeof(Page), typeof(Configuration));
        public Page pagContentFrameSource
        {
            get { return (Page)GetValue(ContentFrameSourceProperty); }
            set { SetValue(ContentFrameSourceProperty, value); }
        }
        public static TinyCinema.Bussiness.HumanResrouces.Configuration dataContext = new TinyCinema.Bussiness.HumanResrouces.Configuration();
        public Configuration()
        {
            InitializeComponent();
            MainMenu = FindResource("MainMenu") as StackPanel;
            DataContext = dataContext;
            (DataContext as Bussiness.HumanResrouces.Configuration).Messenger.Register<Bussiness.HumanResrouces.Message.DeleteFailed>(this, ShowMessageBox1);
            (DataContext as Bussiness.HumanResrouces.Configuration).Messenger.Register<Bussiness.HumanResrouces.Message.DeleteConfirmation>(this, ShowMessageBox2);

        }

        private void MainMenuInitialized(object sender, EventArgs e)
        {
            (sender as StackPanel).DataContext = dataContext;
        }
        DataGrid dtgFocusing;
        private void DataGrid_GotFocus(object sender, RoutedEventArgs e)
        {
            dtgFocusing = sender as DataGrid;
        }
        private void Delete(object sender, RoutedEventArgs e)
        {
            dataContext.DeleteCommand.Execute(dtgFocusing.SelectedValue);

        }
        private void Edit(object sender, EventArgs e)
        {
            (DataContext as Bussiness.HumanResrouces.Configuration).EditCommand.Execute(((sender as DataGrid).SelectedItem));
        }
        void ShowMessageBox1(Bussiness.HumanResrouces.Message.DeleteFailed s)
        {
            if (dtgFocusing == dtgDepartment)
                MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgHumanNotDeleteDepartment") as String), "", MessageBoxButton.OK);
            else MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgHumanNotDeletePosition") as String), "", MessageBoxButton.OK);
            
        }
        void ShowMessageBox2(Bussiness.HumanResrouces.Message.DeleteConfirmation s)
        {
            if (dtgFocusing == dtgDepartment)
                s.Result = MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgHumanDeleteDepartment") as String), "", MessageBoxButton.YesNo);
            else s.Result = MessageBoxUtils.WPFMessageBox.Show((App.Current.FindResource("langMsgHumanDeletePosition") as String), "", MessageBoxButton.YesNo);
        }
    }
}
